if(typeof window.XMLHttpRequest === "undefined"){
    window.XMLHttpRequest = function(){
        return new window.ActiveXObject(navigator.userAgent.indexOf("MSIE 5") >=0 ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP");
    };
}

(function () {
z.net = {
     ajaxSettings: {
        url: location.href,
        global: true,
        type: "GET",
        contentType: "application/x-www-form-urlencoded",
        processData: true,
        async: true,
        /*
        timeout: 0,
        data: null,
        username: null,
        password: null,
        traditional: false,
        */
        // This function can be overriden by calling jQuery.ajaxSetup
        xhr: function() {
            return new window.XMLHttpRequest();
        },
        accepts: {
            xml: "application/xml, text/xml",
            html: "text/html",
            script: "text/javascript, application/javascript",
            json: "application/json, text/javascript",
            text: "text/plain",
            _default: "*/*"
        }
    },
    
    ajaxSetup: function( settings ) {
        z.net.ajaxSettings = z.extend(z.net.ajaxSettings, settings );
    },
    
    get: function (url, data, callback, type) {
        return z.net.ajax({
            type: 'GET',
            url: url,
            data: data,
            success: callback,
            dataType: type
        });
    },
    
    getJSON: function (url, data, callback) {
        return z.net.get(url, data, callback, 'json');
    },
    
    post: function (url, data, callback, type) {
        return z.net.ajax({
            type: 'POST',
            url: url,
            data: data,
            success: callback,
            dataType: type
        });
    },
    httpSuccess: function (r) {
        try{
            return (!r.status && location.protocol == "file:")
            || (r.status>=200 && r.status<300)
            || (r.status==304)
            || (navigator.userAgent.indexOf("Safari")>-1 && typeof r.status=="undefined");
        }catch(e){}
        return false;
    },
    ajax: function (origSettings) {
        var s = z.extend(z.net.ajaxSettings, origSettings);
        
        if ( s.data && s.processData && typeof s.data !== "string" ) {
            s.data = z.net.param( s.data);
        }

        var xhr = s.xhr();

        if ( !xhr ) {
            return;
        }
        xhr._isTimeout = false;
        
        if ( s.username ) {
            xhr.open(s.type, s.url, s.async, s.username, s.password);
        } else {
            xhr.open(s.type, s.url, s.async);
        }

        // Need an extra try/catch for cross domain requests in Firefox 3
        try {
            if (s.contentType) {
                xhr.setRequestHeader("Content-Type", s.contentType);
            }
            
            // Set the Accepts header for the server, depending on the dataType
            xhr.setRequestHeader("Accept", s.dataType && s.accepts[ s.dataType ] ?
                s.accepts[ s.dataType ] + ", */*; q=0.01" :
                s.accepts._default );
        } catch( headerError ) {}
        
        //xhr.abort();

        
        // Wait for a response to come back
        var onreadystatechange = xhr.onreadystatechange = function( isTimeout ) {
            if (xhr.readyState == 4) {
                if (!xhr._isTimeout) {
                    if (z.net.httpSuccess(xhr)) {
                        if (s.success) {
                            s.success(xhr);
                        }
                    }
                }
            }
        };


        // Timeout checker
        if ( s.async && s.timeout > 0 ) {
            setTimeout(function() {
                // Check to see if the request is still happening
                if ( xhr && !xhr._isTimeout ) {
                    xhr._isTimeout = true;
                }
            }, s.timeout);
        }

        // Send the data
        try {
            xhr.send(s.data == null ? null : s.data );

        } catch( sendError ) {
            
        }

        // firefox 1.5 doesn't fire statechange for sync requests
        if ( !s.async ) {
            onreadystatechange();
        }

        // return XMLHttpRequest to allow aborting the request etc.
        return xhr;
    }
};
})();